#!/bin/bash

echo "========================================"
echo "WebSocket 聊天服务器启动脚本"
echo "========================================"
echo

echo "检查 Node.js 是否安装..."
if ! command -v node &> /dev/null; then
    echo "错误: 未找到 Node.js，请先安装 Node.js"
    echo "下载地址: https://nodejs.org/"
    exit 1
fi

echo "Node.js 已安装"
echo

echo "检查依赖是否安装..."
if [ ! -d "node_modules" ]; then
    echo "安装依赖..."
    npm install ws
else
    echo "依赖已存在"
fi

echo
echo "启动 WebSocket 服务器..."
echo "按 Ctrl+C 停止服务器"
echo

node websocket-server.js 